package com.leyou.item.web;

import com.leyou.order.pojo.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * lcd  2020/6/4
 * Description:
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //根据父节点id查询商品分类
    @GetMapping("/list")
    public ResponseEntity<List<Category>> queryListByPid(@RequestParam("pid") Long pid){
        return ResponseEntity.ok(categoryService.queryListByPid(pid));
    }
    @PostMapping
    public ResponseEntity<String> insert(@RequestBody Category category) {
        return ResponseEntity.ok(categoryService.save(category));
    }
    @PatchMapping
    public ResponseEntity<String> update(@RequestBody Category category) {
        return ResponseEntity.ok(categoryService.update(category));
    }
    @DeleteMapping("/{id}")
    public ResponseEntity<String> delete(@PathVariable long id) {
        return ResponseEntity.ok(categoryService.delete(id));
    }

    @GetMapping("/list/ids")
    public ResponseEntity<List<Category>> queryListByIds(@RequestParam("ids") List<Long> ids) {
        return ResponseEntity.ok(categoryService.queryByIds(ids));
    }
}
